/*

Copyright (C) 2007 Thomas Geiger (tom.geiger@gmail.com)

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

*/

#ifndef GRIDFTPCLIENT_H_
#define GRIDFTPCLIENT_H_

#include <globus_ftp_client.h>

#include "URL.h"
#include "XIOClient.h"

namespace globus_io {

using namespace globus_common;
using namespace globus_xio;
	
typedef globus_i_ftp_client_handle_t * globus_ftp_client_handle_t;

/**
 * This class provides GridFTP/FTP functionality
 */
class GridFTPClient
{
	public:
		/**
		 * Constructor
		 */
		GridFTPClient();
		/**
		 * Destructor
		 */
		virtual ~GridFTPClient();
		/**
		 * Receives data of a remote file
		 */
		bool get(URL* remotefile, ostream data);
		/**
		 * Sends data to a remote location
		 */
		bool put(istream data, URL* remotefile);
		/**
		 * Initiates GridFTP 3rd party transfer between two hosts
		 */
		bool transfer(URL* localfile, URL* remotefile);
		/**
		 * Renames a file
		 */
		bool rename(URL* originalfile, string& newfile);
		/**
		 * Checks if a file exists
		 */
		bool exists(URL* remotefile);
		/**
		 * Deletes a file
		 */
		bool del(URL* remotefile);
		/**
		 * Returns the size of a file (kb)
		 */
		int size(URL* remotefile);
		/**
		 * Creates a directory
		 */
		bool mkdir(URL* remotefile);
		/**
		 * Removes a directory
		 */
		bool rmdir(URL* remotefile);
		//bool list(GlousURL* remotedir, vector<string>& filelist);
	private:
		globus_result_t result;
		globus_ftp_client_handle_t handle;
		globus_ftp_client_handleattr_t handle_attr;
		globus_ftp_client_operationattr_t operation_attr;
		globus_ftp_client_operationattr_t dest_attr;		
		void test_error(globus_result_t res, int line);
		XIOClient xio_client;
};

}

#endif /*GLOBUSGRIDFTPCLIENT_H_*/
